package com.course.design.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.course.design.dao.DeptMapper;
import com.course.design.entity.Dept;
import com.course.design.service.DeptService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述:
 *
 * @author qinlianji
 * @create 2020-03-15
 */
@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> queryList() {
        LambdaQueryWrapper<Dept> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Dept::getSjyxbjFg, 1);
        return deptMapper.selectList(wrapper);
    }

    @Override
    public void saveOrUpdate(Dept dept) {
        if (StringUtils.isNotEmpty(dept.getDeptbsId())){
            deptMapper.updateById(dept);
        }else {
            deptMapper.insert(dept);
        }
    }

    @Override
    public void deleteById(String deptbsId) {
        deptMapper.deleteById(deptbsId);
    }

    @Override
    public void batchDeleteById(String ids) {
        deptMapper.batchDelete(ids);
    }

    @Override
    public IPage<Dept> queryPage(int start, int limit, String deptname) {
        return deptMapper.queryPage(new Page<>(start, limit), deptname);
    }
}
